package com.fjeld.client.gui.util.factories;

import com.fjeld.middleware.jaxb.V1Node;
import static com.fjeld.middleware.constants.FontConstants.HEADER_FONT_NORMAL;
import static com.fjeld.swingx.ColorConstants.TEXT_PICKER;

import javax.swing.*;
import java.util.Observer;
import java.util.Observable;

/**
 * Created by IntelliJ IDEA.
 * User: fjelds
 * Date: Apr 2, 2010
 * Time: 5:56:41 PM
 *
 * Observes a node as well as displaying it. When someone clicks this label it will
 * manage the progress of the node as well.
 */
public class JNodeLabel extends JLabel implements Observer
{
    private V1Node actionNode;

    public JNodeLabel(V1Node actionNode)
    {
        super(actionNode.getStatus(), JLabel.LEFT);
        this.actionNode = actionNode;
        setForeground(TEXT_PICKER);
        setFont(HEADER_FONT_NORMAL);
        setBorder(BorderFactory.createEmptyBorder(3, 10, 3, 10));
        actionNode.addObserver(this);
    }

    public void update(Observable observable, Object o)
    {
        if (!getText().equals(actionNode.getStatus()))
        {
            setText(actionNode.getStatus());
            repaint();
        }
    }
}
